﻿@model Associativy.Administration.Models.AssociativyNodeManagementPart
@{
    Script.Require("jQueryUI_Tabs").AtFoot();
    Script.Require("AssociativyFrontends_AutoComplete").AtFoot();
    Style.Require("jQueryUI_Orchard");
}
<fieldset>
    <legend>@T("Associativy graph settings")</legend>
    <div id="associativy-tabs">
        <ul>
            @foreach (var provider in Model.GraphDescriptors)
            {
                <text><li><a href="#associativy-tabs-@provider.Name">@provider.DisplayName.Text</a></li></text>
            }
        </ul>
        @{
            int labelsIndex = 0;
        }
        @foreach (var provider in Model.GraphDescriptors)
        {
            <text>
            <div id="associativy-tabs-@provider.Name">
                <fieldset>
                    <legend>@T("Edit connections")</legend>
                    <ol>
                        @if (Model.NeighbourValues[labelsIndex].ShowLabels)
                        {
                            <li>
                                @Html.Label("NeighbourValues[" + labelsIndex + "].Labels", T("Neighbours").Text)
                                @Html.TextBox("NeighbourValues[" + labelsIndex + "].Labels", Model.NeighbourValues[labelsIndex].Labels, new { @class = "text large" })
                            </li>
                        }
                        else
                        {
                            <li>
                                @Html.Label("NeighbourValues[" + labelsIndex + "].AddLabels", T("Add neighbours").Text)
                                @Html.TextBox("NeighbourValues[" + labelsIndex + "].AddLabels", Model.NeighbourValues[labelsIndex].AddLabels, new { @class = "text large" })
                            </li>
                            <li>
                                @Html.Label("NeighbourValues[" + labelsIndex + "].RemoveLabels", T("Remove neighbours").Text)
                                @Html.TextBox("NeighbourValues[" + labelsIndex + "].RemoveLabels", Model.NeighbourValues[labelsIndex].RemoveLabels, new { @class = "text large" })
                            </li>
                        }
                    </ol>
                    <span class="hint">@T("Type labels of neighbours here, separate by commas. After the first few letters the labels are auto-completed.")</span>
                </fieldset>
            </div>
            @using (Script.Foot())
            {
                <script type="text/javascript">
                    $(function () {
                        $("#associativy-tabs-@provider.Name").find("input[type=text]").each(function () {
                            $.associativy.autoComplete.labels("#" + $(this).attr("id"), "@Url.Action("FetchSimilarLabels", "AutoComplete", new { Area = "Associativy.Frontends", GraphName = provider.Name })");
                        });
                    });
                </script>
            }
            </text>
            labelsIndex++;
        }
    </div>
</fieldset>
@using (Script.Foot())
{
    <script type="text/javascript">
        $(function () {
            $("#associativy-tabs").tabs();
        });
    </script>
}